package com.woniuxy.educationplatform.mapper;

import com.woniuxy.educationplatform.bean.KnowpointBean;
import com.woniuxy.educationplatform.bean.SectionBean;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

@Mapper
public interface KnowpointMapper {

    @Results({
            @Result(id = true, property = "id", column = "id", javaType = Long.class),
            @Result(property = "knowpointNo", column = "knowpoint_no", javaType = String.class),
            @Result(property = "knowpointName", column = "knowpoint_name", javaType = String.class),
            @Result(property = "createTime", column = "create_time", javaType = Date.class),
            @Result(property = "subjectBean", column = "fk_subject_id", javaType = SectionBean.class, one =
            @One(select = "com.woniuxy.educationplatform.mapper.SubjectMapper.findById", fetchType = FetchType.LAZY))
    })
    @Select("select * from knowpoint where id = #{id}")
    KnowpointBean findById(Long id);

    @Results({
            @Result(id = true, property = "id", column = "id", javaType = Long.class),
            @Result(property = "knowpointNo", column = "knowpoint_no", javaType = String.class),
            @Result(property = "knowpointName", column = "knowpoint_name", javaType = String.class),
            @Result(property = "createTime", column = "create_time", javaType = Date.class),
            @Result(property = "subjectBean", column = "fk_subject_id", javaType = SectionBean.class, one =
            @One(select = "com.woniuxy.educationplatform.mapper.SubjectMapper.findById", fetchType = FetchType.LAZY))
    })
    @Select("select * from knowpoint")
    List<KnowpointBean> findAll();

    @Insert("insert into knowpoint (knowpoint_no,knowpoint_name,fk_subject_id,create_time) values(#{k.knowpointNo},#{k.knowpointName},#{k.subjectBean.id},now())")
    void saveKnowpointBean(@Param("k") KnowpointBean knowpointBean);

    @Delete("delete from knowpoint where id = #{id}")
    void delete(Long id);

    void update(@Param("k") KnowpointBean knowpointBean);


    List<KnowpointBean> findOneByCondition(@Param("k") KnowpointBean knowpointBean);

    @Select("select knowpoint_name from knowpoint")
    String[] getknowpoint();
}
